package org.hq.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
 * 工具注入 bean
 */
@Configuration
public class ToolConfig {

    /**
     * redis 工具配置
     *
     * @param redisConnectionFactory
     * @return
     */
    @Bean
    public RedisTemplate<String, String> redisString(@Autowired LettuceConnectionFactory redisConnectionFactory) {
        RedisTemplate<String, String> redis = new RedisTemplate<>();
        redis.setConnectionFactory(redisConnectionFactory);
        //设置 redis key 字符串
        redis.setKeySerializer(RedisSerializer.string());
        //设置 redis Value 为 json 数据
        redis.setValueSerializer(RedisSerializer.string());

        //设置 redis hash key 字符串
        redis.setHashKeySerializer(RedisSerializer.string());
        //设置 redis hash Value 为 json 数据
        redis.setHashValueSerializer(RedisSerializer.string());
        return redis;

    }
}
